package com.buydeem.observer;

/**
 * 观察者模式示例代码
 *
 * @author zengchao
 * @date 2022-04-19 16:15:15
 */
public class App {
    public static void main(String[] args) {
        //创建刘德华话题
        Subject subject = new LdhSubject();
        //创建粉丝
        Fans mac = new Fans("mac");
        Fans jack = new Fans("jack");
        Fans rose = new Fans("rose");
        //订阅刘德华话题
        subject.registerObserver(mac);
        subject.registerObserver(jack);
        subject.registerObserver(rose);
        //发布刘德华结婚消息
        subject.notifyObservers("天王已经悄悄结婚");
        //rose取关
        subject.removeObserver(rose);
        //发布刘德华新电影上线
        subject.notifyObservers("《天下无贼》影院上线了");
    }
}
